package com.geek.image.config;

import com.geek.image.domain.ImageSotreManager;
import com.geek.image.util.BeanFinder;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
public class ImageConfigurer {
    @Autowired
    private ImageStoreProperties storeProperties;
    @Autowired
    private BeanFinder beanFinder;   // 从spring容器中取对象的工具

    @Bean
    public ImageSotreManager tradeRegister() {
        ImageSotreManager register = new ImageSotreManager();

        ImageStoreProperties.Provider[] providers = storeProperties.getProviders();

        for (int i = 0; i < providers.length; i++) {
            register.setImageStore(providers[i].getCode(), beanFinder.findOne(providers[i].getImageSotreClass()));
        }

        return register;
    }
}
